package tmall.controller.front;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import tmall.pojo.User;
import tmall.service.UserService;

@Controller
public class lostController {

    @Autowired
    UserService userService;
    User user = new User();
    @RequestMapping("/lost")
    public String lost() {
        return "pwdlost";
    }

    @RequestMapping("/lostUpdate")
    public String lostUpdate(String name, String password, ModelMap modelMap) {

        try {
            if (userService.isExist(name)) {
                User temp = new User();
                temp.setName(name);
                temp.setPassword(password);
                userService.lostUpdate(temp);

                return "login";
            }
            else{
                modelMap.addAttribute("msg", "抱歉，亲，不存在拥有此用户名的用户");
                return "pwdlost";
            }
        } catch (Exception e) {

            e.printStackTrace();
            return "500";
        }
    }
}
